package com.conferences.web;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.conferences.model.User;

@Controller
public class HomeController extends App {

	@RequestMapping(value = "/home.htm", method = RequestMethod.GET)
	public String loadHome(ModelMap model) {

		org.springframework.security.core.userdetails.User user = (org.springframework.security.core.userdetails.User) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		User userObj = userService.findByUsername(user.getUsername());
		User userObject = userService.get(userObj.getId());

		model.addAttribute("loggedUser", userObject);
		return "home";
	}

	@RequestMapping(value = "/admin.htm", method = RequestMethod.GET)
	public String loadAdminHome(ModelMap model) {
		return "admin_home";
	}
}
